package cn.edu.njust.alg.leetcode;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 创建时间：2015年6月15日 上午11:47:37 项目名称：AlgorithmExercise
 * 
 * @author Zhou Xiumin
 * @version 1.0
 * @since JDK 1.7.0_21 文件名称：Leetcode_0_t.java 类说明：
 */
public class Leetcode_179_Largest_Number {

	public static String largestNumber(int[] nums) {
		String[] ns = new String[nums.length];
		for (int i = 0; i < nums.length; i++) {
			ns[i] = String.valueOf(nums[i]);
		}
		Arrays.sort(ns, new Comparator<String>() {

			@Override
			public int compare(String a, String b) {
				String ab = a.concat(b);
				String ba = b.concat(a);
				return ba.compareTo(ab);
			}

		});
		StringBuffer sb = new StringBuffer();
		for (String s : ns) {
			sb.append(s);
		}
		int count = 0;
		while (count < sb.length() && sb.charAt(count) == '0') {
			count++;
		}
		if (count == sb.length()) {
			return "0";
		}
		return sb.substring(count);
	}

	public static void main(String[] args) {
		int[] nums = { 1, 0 };
		System.out.println(largestNumber(nums));

	}

}
